package com.bwie.bwedu.model.impl;

import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.bwie.bwedu.bean.response.UserResponse;
import com.bwie.bwedu.model.ILoginModel;
import com.bwie.bwedu.utils.ASimpleCacheUtils;
import com.bwie.bwedu.utils.LogUtils;
import com.bwie.bwedu.volley.RequestAPI;

/**
 * Created by Administrator on 2016/7/22.
 */
public class LoginModelImpl implements ILoginModel {
    @Override
    public void login(String username, String pwd, final LoginListener listener) {
        RequestAPI.login(username, pwd, new Response.Listener<UserResponse>() {
            @Override
            public void onResponse(UserResponse baseResponse) {
                if (baseResponse.ok==true){
                    listener.onLoginSuccess();
                    ASimpleCacheUtils.write("tk",baseResponse.tk);
                    LogUtils.e("============"+baseResponse.tk);
                    ASimpleCacheUtils.write("username",baseResponse.user.xm);
                }else{
                    listener.onLoginFail(baseResponse.msg+"");
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError volleyError) {
                listener.onLoginFail("请检查网络");
            }
        });
    }
}
